package com.sikaryofficial.system.controller;

import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.system.domain.PointReq;
import com.sikaryofficial.system.domain.SysMenuNewSaveReq;
import com.sikaryofficial.system.domain.dto.SysMenuNewResp;
import com.sikaryofficial.system.manager.SysMenuNewManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : wuweihong
 * @desc : TODO  请填写你的功能描述
 * @date : 2025-08-11
 */

@Api(tags = {"h5菜单管理"})
@RestController
@RequestMapping("/menu/new")
public class SysMenuNewController {

	@Autowired
	private SysMenuNewManager sysMenuNewManager;

	/**
	 * 获取菜单列表
	 */
	@ApiOperation(value = "获取菜单列表", notes = "获取菜单列表", httpMethod = "GET")
	@PostMapping("/h5/list")
	public R<List<SysMenuNewResp>> getSysMenus(@RequestBody PointReq pointReq) {
		return R.ok(sysMenuNewManager.getMenuByCountry(pointReq));
	}

	@ApiOperation(value = "获取所有菜单列表", notes = "获取所有菜单列表", httpMethod = "GET")
	@GetMapping("/backend/list")
	public R<List<SysMenuNewResp>> getAllMenu(@RequestParam(value = "country", required = false) String country) {
		return R.ok(sysMenuNewManager.getAllMenu(country));
	}

	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "path", dataType = "long", name = "menuId", value = "", required = true)
	})
	@ApiOperation(value = "获取子菜单列表", notes = "获取子菜单列表", httpMethod = "GET")
	@GetMapping("/children/{menuId}")
	public R<List<SysMenuNewResp>> getChildren(@PathVariable("menuId") Long menuId) {
		return R.ok(sysMenuNewManager.getChildren(menuId));
	}

	/**
	 * 新增菜单项
	 */
	@ApiImplicitParams({
			@ApiImplicitParam(paramType = "body", dataType = "SysMenuNewSaveReq", name = "saveReq", value = "", required = true)
	})
	@ApiOperation(value = "新增菜单项", notes = "新增菜单项", httpMethod = "POST")
	@PostMapping("")
	public R<Void> saveOrUpdate(@Validated @RequestBody SysMenuNewSaveReq saveReq) {
		sysMenuNewManager.saveOrUpdate(saveReq);
		return R.ok();
	}

}
